<html>
<head><meta charset="utf-8"><title>Unable to borrow mutable ref immutablty · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Unable.20to.20borrow.20mutable.20ref.20immutablty.html">Unable to borrow mutable ref immutablty</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="178072110"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Unable%20to%20borrow%20mutable%20ref%20immutablty/near/178072110" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Paul Faria <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Unable.20to.20borrow.20mutable.20ref.20immutablty.html#178072110">(Oct 14 2019 at 04:35)</a>:</h4>
<p>So I'm having trouble understanding why the fn on the <code>&amp;'a mut</code>  impl fails to compile, while the one on the <code>&amp;'a</code> impl is fine: <a href="https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2018&amp;gist=bdad95e5ab1ba448eeb61fd93222f34d" target="_blank" title="https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2018&amp;gist=bdad95e5ab1ba448eeb61fd93222f34d">https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2018&amp;gist=bdad95e5ab1ba448eeb61fd93222f34d</a></p>
<p>Is there something going on with auto-(de)ref that I'm not realizing here?</p>



<a name="178073138"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Unable%20to%20borrow%20mutable%20ref%20immutablty/near/178073138" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dylan MacKenzie (ecstatic-morse) <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Unable.20to.20borrow.20mutable.20ref.20immutablty.html#178073138">(Oct 14 2019 at 04:51)</a>:</h4>
<p>I believe this occurs because <code>&amp;T</code> is <code>Copy</code>, but <code>&amp;mut T</code> is not</p>



<a name="178073233"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Unable%20to%20borrow%20mutable%20ref%20immutablty/near/178073233" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dylan MacKenzie (ecstatic-morse) <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Unable.20to.20borrow.20mutable.20ref.20immutablty.html#178073233">(Oct 14 2019 at 04:53)</a>:</h4>
<p>Really what you end up with is a reborrow in the impl for <code>&amp;mut str</code> (<code>&amp;*self.val</code>), which should make the reasoning for the error you're getting clearer.</p>



<a name="178100995"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Unable%20to%20borrow%20mutable%20ref%20immutablty/near/178100995" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Paul Faria <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Unable.20to.20borrow.20mutable.20ref.20immutablty.html#178100995">(Oct 14 2019 at 13:06)</a>:</h4>
<p>Ok. I had considered reborrowing but forgotten about the <code>Copy</code> behavior. That makes so much more sense. Thank you!</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>